'use strict'
let fs = require('fs')
let path = __dirname

function getTemplateInfo(name) {
    var temp = {}
    fs.readdirSync(path + '/' + name).forEach(function(file) {
        if (/^\d+.js$/.test(file)) {
            var templateInfo = require(path + '/' + name + '/' + file)
            for (let i in templateInfo) {
                temp[i] = templateInfo[i]
                temp[i]['templateId'] = i
                temp[i]['type'] = Math.floor(i / 10000)
                if (templateInfo[i].name) {
                    propName[i] = templateInfo[i].name
                }
            }
        }
    })
    return temp
}

//所有模板信息
let totalConfig = {}
let propName = {} //发送给客户端的信息 id => name
fs.readdirSync(path).forEach(function(file) {
    let stat = fs.lstatSync(path + '/' + file)
    if (stat.isDirectory()) {
        totalConfig[file] = getTemplateInfo(file)
    }
})

exports.totalConfig = totalConfig
exports.propName = propName
